package com.amorcloud.pig.receiver;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.smartahc.android.smartble.constant.Constant;

public class BleReceiver extends BroadcastReceiver {
    SearchConnectionListner listner;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d("leihuiming", "action = " + action);
        switch (action) {
            case Constant.BLE_MESSAGE_DEVICE_FOUND:
                if(listner != null) {
                    listner.onDeviceFound((BluetoothDevice) intent.getParcelableExtra(Constant.BLE_DEVICE_DATA));
                }
                break;
            case Constant.BLE_MESSAGE_DEVICE_CONNECT:
                if(listner != null) {
                    listner.onDeviceConnect();
                }
                break;
            case Constant.BLE_MESSAGE_DEVICE_DISCONNECT:
                if(listner != null) {
                    listner.onDeviceDisConnect((BluetoothDevice) intent.getParcelableExtra(Constant.BLE_DEVICE_DATA));
                }
                break;
            case Constant.BLE_EAR_TAG_PARSE_MSG:
                if(listner != null) {
                    listner.onReveiveData(intent.getStringExtra(Constant.BLE_EAR_TAG_DATA));
                }
                break;
        }
    }

    public void setListner(SearchConnectionListner listner) {
        this.listner = listner;
    }

    public interface SearchConnectionListner {
        void onDeviceFound(BluetoothDevice device);
        void onDeviceConnect();
        void onDeviceDisConnect(BluetoothDevice device);
        void onReveiveData(String data);
    }
}
